package com.lzc.springboot.controller;

import com.lzc.springboot.domain.ResultInfo;
import com.lzc.springboot.domain.ShowDisease;
import com.lzc.springboot.domain.TemporaryPicture;
import com.lzc.springboot.service.TemporaryPicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/temporary")
public class TemporaryPicController {

  @Autowired
  private TemporaryPicService picService;

  /**
   * 存储临时图片,并返回图片
   * @param file
   * @throws IOException
   */
  @RequestMapping("/save")
  public ResultInfo<TemporaryPicture> save(@RequestParam("file") MultipartFile file) throws IOException {
    TemporaryPicture picture = new TemporaryPicture();
    picture.setPicName(file.getOriginalFilename());
    picture.setPic(file.getBytes());
    return picService.save(picture);
  }

  /**
   * 删除临时图片
   * @param tempPicId
   */
  @RequestMapping("/delete")
  public void delete(Integer tempPicId){

  }

  /**
   * 识别临时图片
   * @param id
   * @return
   */
  @RequestMapping("/identify")
  public ShowDisease identify(@RequestParam("id") int id){
    return picService.identify(id);
  }
}
